<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<form name="search_files" Action="search_files.html" method="post">
	<table width="750"  cellpadding="0" cellspacing="0" border="0" align="left">
	<tr ><td colspan="6">
			Enter keywords:<input type="text" name="txtkeyword" class="box" style="width: 200px;"/>
			<select name="txtcat" id="txtcat">
				<option value="0">All Categories</option>
				<c:forEach var="y" begin="0" end="${fn:length(categories)-1 }" step="1" varStatus="status">
					<c:if test="${cat_id==categories[y].CATEGORY_ID }">
						<option selected="selected" value="${categories[y].CATEGORY_ID}">
								<c:out value="${categories[y].CATEGORY_NAME}"></c:out>		
						</option>
					</c:if>
					<c:if test="${cat_id!=categories[y].CATEGORY_ID }">
						<option value="${categories[y].CATEGORY_ID}">
								<c:out value="${categories[y].CATEGORY_NAME}"></c:out>		
						</option>
					</c:if>
				</c:forEach>	
			</select>
			<input type="submit" value="Search" style="background-color: #006A9D;border: solid 1px #444;color: #C5C5C5;">
			</td>
		</tr>
		<tr class="table_title" align="center" ><td>FILE ID</td><td>Title</td><td>Short Description</td><td>Size</td><td>Frequency</td><td>Download</td></tr>
		<c:if test="${fn:length(data)>0}">
	<c:forEach var="x" begin="0" end="${fn:length(data)-1}" step="1" varStatus ="status">
		<c:if test="${x>=StartingRow && x<=EndingRow}">
		<tr valign="top">
			<td style="padding-left: 15px;">
			<a href="ViewDetialFile.html?id=${data[x].FILE_ID}">
			<p align="justify">
			<c:out value="${data[x].FILE_ID}"/></p></a></td>
			<td align="left" style="padding-left: 15px;">
			<p align="justify">
			<c:out value="${data[x].FILE_NAME}"/><br/></p></td>
			<td align="left" style="padding-left: 15px;">			
					<c:choose>
						<c:when test="${fn:length(data[x].FILE_DESC)>=80}">
							<p align="justify"><c:out value="${fn:substring(data[x].FILE_DESC,0,80)}"/>...</p>
						</c:when>
						<c:otherwise>
							<p align="justify"><c:out value="${data[x].FILE_DESC}"/></p>
						</c:otherwise>
					</c:choose>
			</td>
			<td align="left" style="padding-left: 15px;">			
			<p align="justify">
			<c:out value="${data[x].FILE_SIZE}"/></p></td>
			
			<td align="left" style="padding-left: 15px;">			
			<p align="justify">
			<c:out value="${data[x].FREQUENCY}"/></p></td>
			
			<td style="padding-left: 20px;">
			<p align="justify">
			<a href="${ServerURL}${data[x].FILE_PATH}${data[x].FILE_NAME}"><img src="images/Download.png" border="0" height=20px width=20px></a>
			</td>
		</tr>
		<tr><td colspan="6">&nbsp;</td></tr>		
		</c:if>
	</c:forEach>
	<tr>
		<td colspan="6" height="30" valign="top">
		<c:if test="${PageCount>1}">
			<c:if test="${page>1}">
				<a href="search_files.html?page=${page-1}">Previous</a>
			</c:if>
			<c:if test="${page<=1}">
				<label style="color: #333">Previous</label>
			</c:if>
			
				<c:forEach var="i" begin="1" end="${PageCount}" step="1" varStatus ="status">
					<c:if test="${i==page}">
						<b style="color: #333"><c:out value="${i}" /></b>
					</c:if>
					<c:if test="${i!=page}">
						<a href="search_files.html?page=${i}"><c:out value="${i}" /></a>
					</c:if>
				</c:forEach>
				
			<c:if test="${page<PageCount}">
				<a href="search_files.html?page=${page+1}">Next</a>
			</c:if>
			<c:if test="${page>=PageCount}">
				<label style="color: #333">Next</label>
			</c:if>
		</c:if>
		</td>
	</tr>
	</c:if>
</table>
</form>
</body>
</html>